function forward2_summary()
% analyze forward2 data, provide a summary.
% data consists of pulse pairs separated by a variable interval
% analysis includes, as a function of the interval:
% spike counts in both intervals for pulse pairs
% STA analysis of rising phase of second pulse
% including spectral content, slope, variance.
%
% This routine takes the results from forward 2, groups them
% by cell, and generates a cell mean curve for FSL and for
% slope and variance.
% 10/27/02 P. Manis
%

global CONTROL

try
   sf = getmainselection;
   if(sf > 0) 
      pflag = getplotflag;
      QueMessage('Forward2 summary', 1); % clear the que
      
      
      fn = {CONTROL(sf).filename}; % get the filenames
      [u, sfu] = unique(fn); % find the unique filenames in the selection
      for j = 1:length(u)
         sf2 = find(strcmp(u{j}, fn)); % find all entries that match the selected names
         slope = [];
         var = [];
         fsl = [];
         for i = 1:length(sf2) % for each file, run through the groups
            nsf = sf(sf2(i)); % this pulls a single entry
            %            fprintf('sf: %d   file: %s recbeg: %d\n', nsf, CONTROL(nsf).filename, CONTROL(nsf).recbeg);
               slope(i,:) = CONTROL(nsf).FWD2.slope;
               var(i,:) = CONTROL(nsf).FWD2.var;
               fs1 = CONTROL(nsf).FWD2.fsl;
               fsl(i,:) = fs1(2:2:end) - fs1(1:2:end);
               mdt = CONTROL(nsf).FWD2.dt;
         end;
         mslope = mean(slope);
         mvar = mean(var);
         mfsl = mean(fsl);
         CONTROL(sf(sf2(1))).FWD2.mslope = mslope; % just store with the first data set.
         CONTROL(sf(sf2(1))).FWD2.mvar = mvar;
         CONTROL(sf(sf2(1))).FWD2.mfsl = mfsl;
      end;
      hf = findobj('tag', 'fwd2summary');
      if(isempty(hf))
         hf = figure('tag', 'fwd2summary');
      end;
      figure(hf);
      clf;
      symc = {'ko', 'k^', 'ks', 'kd'};
      syme = {'ro', 'r^', 'rs', 'rd'};
      n = length(u);
      for j = 1:length(u)
      subplot(3,n,j);
         sf2 = find(strcmp(u{j}, fn)); % find all entries that match the selected names
         ms = CONTROL(sf(sf2(1))).FWD2.mslope;
         dt = CONTROL(sf(sf2(1))).FWD2.dt;
         plot(dt(2:2:end), ms(1:2:end), symc{j}, 'markersize', 3);
         hold on
         plot(dt(2:2:end), ms(2:2:end), syme{j}, 'markersize', 3);
      set(gca, 'Xlim', [0 1200], 'fontsize', 7);
      end;
      for j = 1:length(u)
      subplot(3,n,j+n);
         sf2 = find(strcmp(u{j}, fn)); % find all entries that match the selected names
         ms = CONTROL(sf(sf2(1))).FWD2.mvar;
         dt = CONTROL(sf(sf2(1))).FWD2.dt;
        	plot(dt(2:2:end), ms(1:2:end), symc{j}, 'markersize', 3);
         hold on
         plot(dt(2:2:end), ms(2:2:end), syme{j}, 'markersize', 3);
      set(gca, 'Xlim', [0 1200], 'fontsize', 7);
      end;
      
      for j = 1:length(u)
      subplot(3,n,j+2*n);
         sf2 = find(strcmp(u{j}, fn)); % find all entries that match the selected names
         ms = CONTROL(sf(sf2(1))).FWD2.mfsl;
         dt = CONTROL(sf(sf2(1))).FWD2.dt;
         plot(dt(2:2:end), ms, syme{j}, 'markersize', 3);
         hold on
      set(gca, 'Xlim', [0 1200], 'fontsize', 7);
   end;

   end;

catch
   watchoff;
   QueMessage('Error in Forward2 summary routine', 1);
end;
